package com.majorty.mb.controller;

import com.majorty.mb.controller.response.BaseResponse;
import com.majorty.mb.controller.response.CodeEnum;
import com.majorty.mb.controller.response.ResponseResult;
import com.majorty.mb.util.BeanUtils;
import com.majorty.mb.util.JsonTool;

import org.springframework.stereotype.Controller;

/**
 * @author zhangshuai
 * @date 2019-09-23 10:40
 */
@Controller
public class BaseController {

    /**
     * 生成返回结果{ "code" : 200, "message" : "成功！", "result" : { } }
     * @param result
     * @param code
     * @return json String
     */
    protected String generateResult(Object result, CodeEnum code){
        BeanUtils.defaultProperties(result);
        return JsonTool.dataToJsonWithNull(ResponseResult.out(code, result));
    }

    /**
     * 生成返回结果{ "code" : 200, "message" : "成功！"}
     * @param code
     * @return
     */
    protected String generateResponse(CodeEnum code){
        return JsonTool.dataToJson(BaseResponse.out(code));
    }
}
